import { Widget, _decorator, Node, PageView, tween, v3, Component } from 'cc';
import { GameMgr } from '../manager/GameMgr';
import { Mode } from '../enum/Mode';

const { ccclass, property, requireComponent } = _decorator;

@ccclass('UI/UIMain')
@requireComponent(Widget)
export class UIMain extends Component {
    @property(Node)
    public Button_1: Node | null = null;
    @property(Node)
    public Button_2: Node | null = null;
    @property(Node)
    public Button_3: Node | null = null;

    onLoad() {
        this.AddListener();
    }

    ShowOn() {
        this.node.active = true;
    }

    AddListener() {
        this.Button_1.on(Node.EventType.TOUCH_END, this.On_Button_1, this);
        this.Button_2.on(Node.EventType.TOUCH_END, this.On_Button_2, this);
        this.Button_3.on(Node.EventType.TOUCH_END, this.On_Button_3, this);
    }

    async On_Button_1() {
        // UIMgr.close(UI.Main)
        this.ShowOff();

        GameMgr.mode = Mode.tp
        GameMgr.startGame()
    }
    async On_Button_2() {
        // UIMgr.close(UI.Main)
        this.ShowOff();

        GameMgr.mode = Mode.gs
        GameMgr.startGame()
    }
    async On_Button_3() {
        // UIMgr.close(UI.Main)
        this.ShowOff();

        GameMgr.mode = Mode.ls
        GameMgr.startGame()
    }

    ShowOff() {
        this.node.destroy();
        // this.RemoveListener();
    }
}